Skip to content

FIX: improve CfRadial roundtrips and export after sweep mapping#350

Merged
kmuehlbauer merged 3 commits intoopenradar:mainfrom
syedhamidali:cfradial-followups
Apr 23, 2026
Merged

FIX: improve CfRadial roundtrips and export after sweep mapping#350
kmuehlbauer merged 3 commits intoopenradar:mainfrom
syedhamidali:cfradial-followups

Conversation

@syedhamidali
Copy link
Copy Markdown
Member

Summary

This PR improves the CfRadial1/CfRadial2 transform and export paths in a few places where the current behavior was inconsistent or too fragile.

The main fixes are:

  • make to_cfradial2() work on root-only datasets returned by xr.open_dataset(..., engine="cfradial1") by reopening the original source when available
  • preserve the georeferencing_correction group during CfRadial transforms even when it is empty
  • make CfRadial1 export robust after map_over_sweeps() workflows that use dataset-wide operations like where(), which can broadcast sweep metadata into 2D arrays

What changed

  • xradar/transform/cfradial.py

    • to_cfradial2() now detects the normalized root-only dataset returned by engine="cfradial1"
    • if encoding["source"] is available, it reopens the original CfRadial1 file through open_cfradial1_datatree(...)
    • if not, it raises a clearer error
    • georeferencing_correction is now preserved as a structural group even when it contains no variables
  • xradar/io/export/cfradial1.py

    • normalize sweep metadata variables such as sweep_number, sweep_fixed_angle, and sweep_mode back to scalar form before CfRadial1 export
    • this fixes failures after map_over_sweeps() operations that apply where() and broadcast metadata across (time/azimuth, range)
  • tests/transform/test_cfradial.py

    • added regression tests for:
      • root-only engine="cfradial1" datasets passed into to_cfradial2()
      • missing encoding["source"] on those datasets
      • CfRadial1 export after map_over_sweeps(... where(...))
  • docs/history.md

    • documented the fix in the development history

Motivation

This addresses two related issues:

  1. to_cfradial2() behaved inconsistently depending on how the source dataset was opened
  2. to_cfradial1() / io.to_cfradial1() could fail after map_over_sweeps() even though the transformed tree looked structurally valid

In particular, the exporter previously assumed sweep metadata stayed scalar, which is not true after some dataset-wide masking operations.

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 28, 2026

Codecov Report

❌ Patch coverage is 96.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 93.94%. Comparing base (e8e905a) to head (47d9dcd).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
xradar/io/export/cfradial1.py 95.23% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #350      +/-   ##
==========================================
+ Coverage   93.85%   93.94%   +0.08%     
==========================================
  Files          28       28              
  Lines        6166     6191      +25     
==========================================
+ Hits         5787     5816      +29     
+ Misses        379      375       -4     
Flag Coverage Δ
notebooktests 0.00% <0.00%> (ø)
unittests 93.94% <96.66%> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Collaborator

@kmuehlbauer kmuehlbauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @syedhamidali, this seems reasonable to do. One comment here.

Comment thread xradar/io/export/cfradial1.py
@kmuehlbauer
Copy link
Copy Markdown
Collaborator

@syedhamidali We can move on with this, please fix the merge conflicts and then we can get this in 👍

Copy link
Copy Markdown
Collaborator

@kmuehlbauer kmuehlbauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to fix history.md here. Otherwise LGTM.

Comment thread docs/history.md Outdated
@kmuehlbauer kmuehlbauer enabled auto-merge (squash) April 23, 2026 10:36
@kmuehlbauer kmuehlbauer merged commit 230dbf5 into openradar:main Apr 23, 2026
11 checks passed
@syedhamidali syedhamidali deleted the cfradial-followups branch April 23, 2026 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Bug in Either map_over_sweeps or in to_cfradial1

2 participants